/**
 * get
 */
const get=function ( _url, _data, callback) {
  httpRequest("GET",_url,_data,callback);
}

/**
 * post
 */
const post = function (_url, _data, callback) {
  httpRequest("POST", _url, _data, callback);
}

/**
 * put
 */
const put = function (_url, _data, callback) {
  httpRequest("PUT", _url, _data, callback);
}

/**
 * delete
 */
const Delete = function (_url, _data, callback) {
  httpRequest("DELETE", _url, _data, callback);
}

// /**
//  * patch
//  */
// const patch = function (_url, _data, callback) {
//   httpRequest("PATCH", _url, _data, callback);
// }

/** 
* 封装微信http请求
*/
const httpRequest=function (_method, _url, _data, callback) {
  let _this = this;
  wx.request({
    url: _url,
    header: {
      // 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
      'token': wx.getStorageSync('token')
    },
    method: _method,
    data: _data,
    success: function (res) {
      if (res.data.error_code == '5000') {
        app.globalData.authStatus = true;
        callback(res);
        setTimeout(res=>{
          wx.switchTab({
            url: '/pages/personal/index_2/personal?status=ture'
          })
        },1500)
      } else {
        callback(res);
      }
    },
    fail: function (res) {
      console.log(res);
    }
  })
}

// /**
//  * 获取新的消息盒子
//  */
// const getNewInbox = function(type, callback) {
//   this.get(`/new/${type}/inbox`, {}, function (res) {
//     callback(res);
//   });
// }

// /**
//  * 收集form id
//  */
// const collectFormId = function(formId) {
//   this.post(`/save_form_id`, {
//     form_id: formId
//   }, function (res) {
//     console.log(res);
//   });
// }

module.exports = {get, post, put, Delete, httpRequest}

